//
//  ZTTabBarButton.m
//  DianYing5
//
//  Created by d0 on 15/7/17.
//  Copyright (c) 2015年 uskr. All rights reserved.
//

#import "ZTTabBarButton.h"

@implementation ZTTabBarButton

-(ZTTabBarButton*)initWithLabelRect:(CGRect)labelRect
                  withSelectedImage:(UIImage*)selectedImage
                  withUnselectImage:(UIImage*)unselectImage
                withImageEdgeInsets:(UIEdgeInsets)imageEdgeInsets
                         withAction:(void (^)(ZTTabBarButton * button))action

{
    
    self = [super init];
    
    if(self)
    {
        self.action = action;
        
        self.label = [[UILabel alloc]initWithFrame:labelRect];
        
        self.label.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:self.label];

        [self setImage:selectedImage forState:UIControlStateSelected];

        [self setImage:unselectImage forState:UIControlStateNormal];

        [self setImageEdgeInsets:imageEdgeInsets];

        [self addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

    }

    return self;
}


-(void)btnClick:(ZTTabBarButton*)btn
{
    //判断action是否己经设置,设置了就了调用action;
    if(self.action)
        self.action(btn);
}

//重写这个方法,去掉按钮的高亮状态
-(void)setHighlighted:(BOOL)highlighted
{

}
@end
